from x3trade.api.base import BaseApi
from x3trade.api.data import DataApi 
from x3trade.utils import crypto
from x3trade.schemas import User
from x3trade.models import *
from x3trade.database import get_db, Base, engine, query

def test_base():
    apiKey = "wakeblade"
    apiSecret = crypto.strong(16)
    print(f"apiKey: {apiKey} | apiSecret: {apiSecret}")
    api = BaseApi(apiKey, apiSecret)
    print(f"token: {api.getToken()}")
    api.refresh()
    print(f"token: {api.token}")

def test_register():
    user = User(
        username = "wakeblade",
        password = "masterhero",
        email = "2390245@qq.com",
        mobile = "13424459938",
        # appKey = "wakeblade",
        # appSecret = crypto.strong(32),
        sex = 1,
        is_active = True
    )

    api = DataApi(user.appKey, user.appSecret, "http://192.168.0.108:8080")
    res = api.register(user)
    print(res)

def test_login():
    appKey = "wakeblade"
    appSecret = "Ay7WH7Vk4aU1I7Y4AQte9beBlQqLWzes"
    print(f"appKey: {appKey} | appSecret: {appSecret}")
    api = DataApi(appKey, appSecret, "http://127.0.0.1:8080")
    res = api.login()
    print(api.__dict__)

def test_query():
    db = next(get_db())
    users = query(db, UserModel, appKey="wakeblade")
    print(users)

def test_stock():
    api = DataApi(appKey, appSecret, "http://127.0.0.1:8080")
    res = api.login()

test_stock()